@extends('admin.app')

@section('breadcrumb')
    <div class="bg-light lter b-b wrapper-md">
        <ol class="breadcrumb bg-light lter m-n no-padder">
            <li><a href="{{ admin_action('HomeController@index') }}">主页</a></li>
            <li>业务管理</li>
            <li class="active">用户管理</li>
        </ol>
    </div>
@endsection

@section('content')
    <div class="panel panel-default">
        <div class="panel-heading font-bold">
        投资记录
        </div>
        <div class="row wrapper">
        	<!-- 1 start -->
        	<div class="col-sm-10">
                <form class="form-horizontal" method="get"
                      action="{{admin_action('Business\SalesStatisticsController@index')}}">
                    <div class="row">
                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="control-label col-sm-4">客户:</label>
                                <div class="col-sm-8">
                                    <input class="form-control" type="text" placeholder="姓名" name="username"
                                           value="{{ $query['username'] }}"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="control-label col-sm-4">经纪人:</label>
                                <div class="col-sm-8">
                                    <input class="form-control" type="text" placeholder="姓名" name="broker_name"
                                           value="{{ $query['broker_name'] }}"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-10">
                            <div class="form-group">
                                <label class="control-label col-sm-2">投资时间:</label>
                                <div class="col-sm-4">
                                    
                                    <input type="text" class="form-control datetimepicker" name="start_time"
                                           value="{{ $query['start_time'] }}" placeholder="请选择开始时间">

                                </div>
                                <div class="col-sm-4">
                                    
                                    <input type="text" class="form-control datetimepicker" name="end_time"
                                           value="{{ $query['end_time'] }}" placeholder="请选择结束时间">

                                </div>
                            </div>
                        </div>
                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="control-label col-sm-4">机构:</label>
                                <div class="col-sm-8">
                        <select class="form-control org_yxjg" name="org_code" data-dept-url="{{ admin_action('Business\UsersController@orgDept') }}" data-rule-required="true">
                            <option value="">
                                请选择营销机构
                            </option>
                            @foreach($all_org as $org)
                                <option value="{{ $org->code }}" {{ $query['org_code'] == $org->code?'selected=selected':'' }}>{{ $org->company_name }}({{ $org->description }})</option>
                            @endforeach
                        </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="control-label col-sm-4">部门:</label>
                                <div class="col-sm-8">
                        <select class="form-control org_dept" data-rule-required='true' name='dept_code'>
                            <option value="">
                                请选择机构下属部门
                            </option>
                        </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-1 text-left">
            <span class="input-group-btn">
              <button class="btn btn-sm btn-default" type="submit">查询</button>
            </span>
                        </div>
                    </div>
                </form>
            </div>
            <div class="col-sm-2 text-right text-center-xs">

                <a class="btn btn-xs btn-primary"
                       href="{{ admin_action('Business\SalesStatisticsController@salesStatistics') }}"
                       data-toggle="tooltip" title="销售统计">
                    <i class="fa fa-list-alt"></i>
                </a>
                <a class="btn btn-xs btn-primary"
                       href="{{ admin_action('Business\SalesStatisticsController@brokerList') }}"
                       data-toggle="tooltip" title="经纪人管理">
                    <i class="fa fa-group"></i>
                </a>
                  <a class="btn btn-xs btn-primary"
                       href="{{ admin_action('Business\SalesStatisticsController@userList') }}"
                       data-toggle="tooltip" title="客户管理">
                    <i class="fa fa-user"></i>
                </a>
            </div>
        	<!-- 1 end -->
        </div>
        <div class="table-responsive">
           <table class="table table-striped b-t b-light">
                <thead>
                <tr>
                    @foreach($invest_statistics as $k => $v)    
                        <th>{{ $v['name'] }}</th>
                    @endforeach
                </tr>
                </thead>
                <tbody>
                    <tr>
                    @foreach($invest_statistics as $k => $v)    
                        <td>{{ $v['money'] }}元&nbsp;&nbsp;{{ $v['person_number'] }}人&nbsp;&nbsp;{{ $v['transaction_pen'] }}笔</td>
                    @endforeach
                    </tr>
                </tbody>
            </table>
            <br/>
           <table class="table table-striped b-t b-light">
                <thead>
                <tr>
                    <th>投资流水号</th>
                    <th>客户id</th>
                    <th>客户</th>
                    <th>经纪人id</th>
                    <th>经纪人</th>
                    <th>投资金额</th>
                    <th>投资时间</th>
                    <th>预期收益</th>
                    <th>项目名称</th>
                    <th>投资状态</th>
                    <th>预期还款时间</th>
                </tr>
                </thead>
                <tbody>
                @forelse ($user_invest_list as $invest)
                    <tr>
                        <td>{{ $invest->sn }}</td>
                        <td>{{ $invest->user_id }}</td>
                        <td><a href="sales_statistics/user_list/{{ $invest->user_id }}" data-toggle="tooltip" title="客户详情">{{ $invest->user_name??'--' }}</a></td>
                        <td>{{ $invest->broker_id }}</td>
                        <td><a href="sales_statistics/broker_list/{{ $invest->broker_id }}" data-toggle="tooltip" title="经纪人详情">{{ $invest->broker_name }}</a></td>
                        <td>{{ $invest->invest_money }}</td>
                        <td>{{ $invest->invest_time }}</td>
                        <td>{{ $invest->expected_return }}</td>
                        <td><a href="/oneProjects/{{ $invest->projects_id }}" data-toggle="tooltip" title="项目详情">{{ $invest->projects_name }}</a></td>
                        <td>{{ $invest->invest_status_name }}</td>
                        <td>{{ $invest->trade_finish_date or $invest->trade_repayment_date }}</td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="3" class="text-center">没有找到客户投资记录</td>
                    </tr>
                @endforelse
                </tbody>
            </table>

        </div>
        <div class="panel-footer">
            <div class="row">
                <div class="col-sm-12 text-right text-center-xs">
                {{ $links }}
                </div>
            </div>
        </div>
    </div>
@endsection
@section('scripts')
  <script src="{{ asset('resources/admin/plugins/echarts/echarts.min.js') }}"></script>
    <script type="text/javascript">
        var dept_code = '{{ $query['dept_code'] }}';
        $(function(){
            //动态查询营销机构的部门
            $('.org_yxjg').change(function(){
                $dept_url = $(this).data('dept-url');
                $org_code = $(this).find('option:selected').val();
                $('.org_dept').html("");
                //异步查询营销机构下级部门
                $.ajax({
                    url:$dept_url,
                    data:{org_code:$org_code},
                    success:function(data){
                        node = '';
                        if(data.length > 0){
                            for(var i in data){
                                if(dept_code === data[i]["code"])
                                    node = node+'<option selected=selected value ='+data[i]["code"]+'>'+data[i]["name"]+'</option>';
                                else
                                    node = node+'<option value ='+data[i]["code"]+'>'+data[i]["name"]+'</option>';
                            }
                            $('.org_dept').append($(node));
                        }else{
                            node = node+'<option value ='+""+'>'+"  --  "+'</option>';
                            $('.org_dept').append($(node));
                        }
                    }
                });
            });
            $('.org_yxjg').trigger("change");
        });
	</script>
@endsection